﻿@using PagedList.Mvc;
@model  BBICMS.Application.ViewModels.LanguageListVM
@{
    ViewBag.Title = EntityNames.Language;
    ViewBag.PageTitle = ViewBag.Title + "_内容";
    Layout = "~/Areas/Admin/Views/Shared/_Layout.cshtml";
}


<div class="panel panel-default">
    <header class="panel-heading">
        <span class="glyphicon glyphicon-file"></span> @ViewBag.Title
    </header>

    <section class="panel-body">
        <div class="text-right">
            <a class="btn btn-primary" href="@Url.Action("Add")"><i class="glyphicon glyphicon-plus"></i> @string.Format("{0}{1}", Buttons.Add, EntityNames.Language)</a>          
        </div>
    </section>

    <div class="table-responsive">
        <table class="table table-hover table-vmiddle">
            <thead>
                <tr>
                    <th>
                        图标
                    </th>
                    <th>
                        语言名称
                    </th>
                    <th>
                        语言代码
                    </th>
                    <th>
                        默认？
                    </th>
                    <th>
                        激活？
                    </th>
                    @*<th>
                        <span class="glyphicon glyphicon-user"></span> 发布者
                    </th>
                    <th>
                        <span class="glyphicon glyphicon-time"></span> 创建日期
                    </th>*@
                    <th>
                        操作
                    </th>
                </tr>
            </thead>
            <tbody>
                @foreach (var item in Model.OnePageOfLanguages)
                {
                    <tr class="first">
                        <td>
                          
                                <img src="@item.Icon" alt="@item.FullName" />
                         
                        </td>
                        <td>
                            @item.FullName
                        </td>
                        <td>
                            @item.CultureName
                        </td>
                        <td>
                            @if (item.IsDefault)
                            {
                                <a href="#" data-url="@Url.Action("IsDefault", new {id = item.Id})" class="default-item" title="默认">
                                    <i class="fa fa-check text-success"></i>
                                </a>

                            }
                            else
                            {
                                <a href="#" data-url="@Url.Action("IsDefault", new {id = item.Id})" class="default-item" title="解除默认">
                                    <i class="fa fa-remove text-danger"></i>
                                </a>
                            }                         
                        </td>
                        <td>
                            

                            @if (item.Active)
                            {
                                <a href="#" data-url="@Url.Action("IsActive", new {id = item.Id})" class="active-item" title="锁定">
                                    <i class="fa fa-check text-success"></i>
                                </a>

                            }
                            else
                            {
                                <a href="#" data-url="@Url.Action("IsActive", new {id = item.Id})" class="active-item" title="解锁">
                                    <i class="fa fa-remove text-danger"></i>
                                </a>                                
                            }
                          
                        </td>
                        @*<td>
                            @item.AddedBy
                        </td>
                        <td>@item.AddedDate.ToShortDateString()</td>*@

                     
                        <td>
                            

                           
                            <a href="@Url.Action("Edit", new { Id = item.Id })" class="btn btn-xs btn-primary"><i class="glyphicon glyphicon-edit"></i></a>
                            <a href="@Url.Action("Delete", new { Id = item.Id })" class="btn btn-xs btn-danger btnDelete"><i class="glyphicon glyphicon-trash"></i></a>
                        </td>
                    </tr>
                }

            </tbody>

        </table>



    </div>


    <footer class="panel-footer">
        <ul class="pagination">
            @Html.PagedListPager(Model.OnePageOfLanguages, page => Url.Action("Index", new { page }))
        </ul>
    </footer>
</div>


<form id="anti-form" method="post">
    @Html.AntiForgeryToken()
</form>

<!-- end main container -->
@section footer {

    <script>

        $(function () {

            //锁定 激活
            $('.active-item').click(function (e) {

                e.preventDefault();
                var url = $(this).attr('data-url'), title = $(this).attr('title'), that = $(this);
             
                Common.ActiveItem(url, title, that);              

            });

            //默认
            $('.default-item').click(function (e) {

                e.preventDefault();
                var url = $(this).attr('data-url'), title = $(this).attr('title'), that = $(this);               
                Common.DefaultItem(url, title, that);

            });

        

            //删除数据
            $('.btnDelete').click(function (e) {
                e.preventDefault();
                var url = $(this).attr('href'), that = $(this),  title = '@string.Format("删除{0}",EntityNames.Language)';

                bootbox.setLocale("zh_CN");

                bootbox.confirm("是否确定删除该项？", function (result) {
                    if (result) {
                        $.post(url, $("#anti-form").serialize(), function (data) {

                            if (data.Status === 1) {
                                Common.ShowBox(data.Status, data.Message, title);

                                if (data.Status === 1) {
                                    that.closest('tr').remove();
                                }


                            } else {
                                toastr.error(data.Message, title);
                            }

                        });
                    }
                });
            });




        });
    </script>

}